package handler

import (
	"bytes"
	"encoding/binary"

	"github.com/cz-it/gonnectd/src/proto"
)

type Relay struct {
	Bus chan proto.Body
}

func NewRelay(bus chan proto.Body) *Relay {
	relay := new(Relay)
	relay.Bus = bus
	return relay
}

func (relay *Relay) Proc(body proto.Body) []byte {
	relay.Bus <- body
	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, []byte("RELAY_REP"))
	return buf.Bytes()
}
